@extends('layouts.admin')

@section('title', '荣誉管理-编辑')

@section('content')
    <div id="tab_teacher" class="HuiTab">
        <input type="hidden" id="teacher_id" value="{{$teacher_id}}">
        <div class="tabBar clearfix"><span>进修情况</span><span>著作论文</span><span>证书情况</span></div>
        <div class="tabCon">
            <article class="page-container">
                <table id="listStudyTable" class="table table-border table-bordered table-bg table-hover">
                    <thead>
                    <tr class="text-c">
                        <th><input type="checkbox" name="checkStudyList"/></th>
                        <th>主办方</th>
                        <th>进修内容</th>
                        <th>开始时间</th>
                        <th>结束时间</th>
                        <th>成绩</th>
                        <th>备注</th>
                        <th>创建时间</th>
                    </tr>
                    </thead>
                </table>
            </article>
        </div>
        <div class="tabCon">
            <article class="page-container">
                <table id="listCompositionTable" class="table table-border table-bordered table-bg table-hover">
                    <thead>
                    <tr class="text-c">
                        <th><input type="checkbox" name="checkCompositionList"/></th>
                        <th>名称</th>
                        <th>摘要</th>
                        <th>出版/转载/获奖/交流情况</th>
                        <th>合著/译</th>
                        <th>创造时间</th>
                        <th>备注</th>
                        <th>创建时间</th>
                    </tr>
                    </thead>
                </table>
            </article>
        </div>
        <div class="tabCon">
            <article class="page-container">
                <table id="listCertificateTable" class="table table-border table-bordered table-bg table-hover">
                    <thead>
                    <tr class="text-c">
                        <th><input type="checkbox" name="checkCertificateList"/></th>
                        <th>主办方</th>
                        <th>活动名称</th>
                        <th>奖项名称</th>
                        <th>获得时间</th>
                        <th>名次/得分</th>
                        <th>证书电子件</th>
                        <th>创建时间</th>
                    </tr>
                    </thead>
                </table>
            </article>
        </div>
    </div>
@endsection
@section('script')
    <script>
        $(function(){$("#tab_teacher").Huitab();})
    </script>
    <script>
        var $studyDataTable=null;
        var $STUDY_MAIN={currentPage:1}
        $(function(){
            $studyDataTable=$('#listStudyTable').dataTable({
                "sPaginationType" : "full_numbers",
                "processing": true,
                "serverSide": true,
                "searching": false,
                'ordering':false,
                "dom": '<l<\'#topStudyPlugin\'>f>rt<ip><"clear">',
                "ajax":{
                    "url":"{{url('teacher/study/list')}}",
                    "type": 'post',
                    "data": function ( d ) {
                        d.page=$STUDY_MAIN.currentPage;
                        d.teacher_id='{{$teacher_id}}';
                    },
                    'dataSrc':function(result){
                        var datas=result.data;
                        if(datas){
                            for(var i=0;i<datas.length;i++){
                                datas[i].DT_RowClass='text-c';
                            }
                        }
                        return datas;
                    }
                },
                "columnDefs": [{
                    "targets": "_all",
                    "searchable":false
                }],
                "columns": [
                    {
                        "data": "id",
                        "render": function (data, type, row, meta) {
                            return '<input type="checkbox"  name="checkStudyList" class="checkchild"  value="' + data + '" />';
                        }
                    },
                    { "data": "sponsor"},
                    { "data": "content"},
                    { "data": "start_date" },
                    { "data": "finish_date" },
                    { "data": "score" },
                    { "data": "remark" },
                    { "data": "created_at" },
                ],
                drawCallback: function( settings ) {
                    $('input[name=checkStudyList]')[0].checked=false;
                },
                "initComplete":function(settings, json){
                    var topPlugin='<button class="btn btn-danger radius studyDelSelectBtn"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</button> ' +
                        '<button class="btn btn-primary radius studyAddBtn" ><i class="Hui-iconfont">&#xe600;</i>新增</button>';
                    $("#topStudyPlugin").append(topPlugin);
                }
            });
            $studyDataTable.on( 'page.dt', function () {
                var info = $studyDataTable.api();
                $STUDY_MAIN.currentPage=parseInt(info.page())+1;
            } );
        });

        $STUDY_MAIN.deleteDatas=function(ids){
            layer.confirm('确定要删除选择的进修码？',{
                    btn: ['确定','取消'],
                    shade: false,
                    closeBtn: 0
                },
                function(){
                    $.ajax({
                        url: "{{url('teacher/study/delete')}}",
                        data:{ids:ids},
                        dataType: 'json',
                        success: function(data){
                            if(data['successFlag']==1){
                                layer_success_message('删除成功!');
                                $studyDataTable.api().ajax.reload();
                            }else{
                                layer_error_message(data['msg']);
                            }
                        },
                        error:function(data) {
                            layer_error_message('删除失败!');
                        },
                    });
                });
        }

        $STUDY_MAIN.getSelectCheckBoxValue=function(){
            var theArray=[];
            $("input[name=checkStudyList]:checked").each(function() {
                theArray.push($(this).val());
            });
            return theArray;
        }
        $(function(){
            $(document).on("click",".studyDelSelectBtn",function(){
                var ids=$STUDY_MAIN.getSelectCheckBoxValue();
                if(ids.length<=0){
                    layer.msg('请选择需要删除的进修数据', {icon:5,time:1000});
                }else{
                    $STUDY_MAIN.deleteDatas(ids);
                }
            });
            $(document).on("click",".studyAddBtn",function(){
               layer_show('添加进修','{{url('teacher/study/add')}}?teacher_id={{$teacher_id}}',800,500);
            });
        })
    </script>
    <script>
        var $compositionDataTable=null;
        var $COMPOSITION_MAIN={currentPage:1}
        $(function(){
            $compositionDataTable=$('#listCompositionTable').dataTable({
                "sPaginationType" : "full_numbers",
                "processing": true,
                "serverSide": true,
                "searching": false,
                'ordering':false,
                "dom": '<l<\'#topCompositionPlugin\'>f>rt<ip><"clear">',
                "ajax":{
                    "url":"{{url('teacher/composition/list')}}",
                    "type": 'post',
                    "data": function ( d ) {
                        d.page=$COMPOSITION_MAIN.currentPage;
                        d.teacher_id='{{$teacher_id}}';
                    },
                    'dataSrc':function(result){
                        var datas=result.data;
                        if(datas){
                            for(var i=0;i<datas.length;i++){
                                datas[i].DT_RowClass='text-c';
                            }
                        }
                        return datas;
                    }
                },
                "columnDefs": [{
                    "targets": "_all",
                    "searchable":false
                }],
                "columns": [
                    {
                        "data": "id",
                        "render": function (data, type, row, meta) {
                            return '<input type="checkbox"  name="checkCompositionList" class="checkchild"  value="' + data + '" />';
                        }
                    },
                    { "data": "title"},
                    { "data": "summary"},
                    { "data": "use_honor_description" },
                    { "data": "write_description" },
                    { "data": "acquire_date" },
                    { "data": "remark" },
                    { "data": "created_at" },
                ],
                drawCallback: function( settings ) {
                    $('input[name=checkCompositionList]')[0].checked=false;
                },
                "initComplete":function(settings, json){
                    var topPlugin='<button class="btn btn-danger radius compositionDelSelectBtn"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</button> ' +
                        '<button class="btn btn-primary radius compositionAddBtn" ><i class="Hui-iconfont">&#xe600;</i>新增</button>';
                    $("#topCompositionPlugin").append(topPlugin);
                }
            });
            $compositionDataTable.on( 'page.dt', function () {
                var info = $compositionDataTable.api();
                $COMPOSITION_MAIN.currentPage=parseInt(info.page())+1;
            } );
        });

        $COMPOSITION_MAIN.deleteDatas=function(ids){
            layer.confirm('确定要删除选择的著作吗？',{
                    btn: ['确定','取消'],
                    shade: false,
                    closeBtn: 0
                },
                function(){
                    $.ajax({
                        url: "{{url('teacher/composition/delete')}}",
                        data:{ids:ids},
                        dataType: 'json',
                        success: function(data){
                            if(data['successFlag']==1){
                                layer_success_message('删除成功!');
                                $compositionDataTable.api().ajax.reload();
                            }else{
                                layer_error_message(data['msg']);
                            }
                        },
                        error:function(data) {
                            layer_error_message('删除失败!');
                        },
                    });
                });
        }

        $COMPOSITION_MAIN.getSelectCheckBoxValue=function(){
            var theArray=[];
            $("input[name=checkCompositionList]:checked").each(function() {
                theArray.push($(this).val());
            });
            return theArray;
        }
        $(function(){
            $(document).on("click",".compositionDelSelectBtn",function(){
                var ids=$COMPOSITION_MAIN.getSelectCheckBoxValue();
                if(ids.length<=0){
                    layer.msg('请选择需要删除的著作数据', {icon:5,time:1000});
                }else{
                    $COMPOSITION_MAIN.deleteDatas(ids);
                }
            });
            $(document).on("click",".compositionAddBtn",function(){
                layer_show('添加著作','{{url('teacher/composition/add')}}?teacher_id={{$teacher_id}}',800,500);
            });
        })
    </script>
    <script>
        var $certificateDataTable=null;
        var $CERTIFICATE_MAIN={currentPage:1}
        $(function(){
            $certificateDataTable=$('#listCertificateTable').dataTable({
                "sPaginationType" : "full_numbers",
                "processing": true,
                "serverSide": true,
                "searching": false,
                'ordering':false,
                "dom": '<l<\'#topCertificatePlugin\'>f>rt<ip><"clear">',
                "ajax":{
                    "url":"{{url('teacher/certificate/list')}}",
                    "type": 'post',
                    "data": function ( d ) {
                        d.page=$CERTIFICATE_MAIN.currentPage;
                        d.teacher_id='{{$teacher_id}}';
                    },
                    'dataSrc':function(result){
                        var datas=result.data;
                        if(datas){
                            for(var i=0;i<datas.length;i++){
                                datas[i].DT_RowClass='text-c';
                            }
                        }
                        return datas;
                    }
                },
                "columnDefs": [{
                    "targets": "_all",
                    "searchable":false
                }],
                "columns": [
                    {
                        "data": "id",
                        "render": function (data, type, row, meta) {
                            return '<input type="checkbox"  name="checkCertificateList" class="checkchild"  value="' + data + '" />';
                        }
                    },
                    { "data": "sponsor"},
                    { "data": "title"},
                    { "data": "acquire_date" },
                    { "data": "awards_name" },
                    { "data": "score" },
                    { "data": "electron_attachment",
                        "render": function (data, type, row, meta) {
                            return '<img src="'+data+'" width="100px" class="thumbnail">';
                        }
                    },
                    { "data": "created_at" },
                ],
                drawCallback: function( settings ) {
                    $('input[name=checkCertificateList]')[0].checked=false;
                },
                "initComplete":function(settings, json){
                    var topPlugin='<button class="btn btn-danger radius certificateDelSelectBtn"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</button> ' +
                        '<button class="btn btn-primary radius certificateAddBtn" ><i class="Hui-iconfont">&#xe600;</i>新增</button>';
                    $("#topCertificatePlugin").append(topPlugin);
                }
            });
            $certificateDataTable.on( 'page.dt', function () {
                var info = $certificateDataTable.api();
                $CERTIFICATE_MAIN.currentPage=parseInt(info.page())+1;
            } );
        });

        $CERTIFICATE_MAIN.deleteDatas=function(ids){
            layer.confirm('确定要删除选择的证书吗？',{
                    btn: ['确定','取消'],
                    shade: false,
                    closeBtn: 0
                },
                function(){
                    $.ajax({
                        url: "{{url('teacher/certificate/delete')}}",
                        data:{ids:ids},
                        dataType: 'json',
                        success: function(data){
                            if(data['successFlag']==1){
                                layer_success_message('删除成功!');
                                $certificateDataTable.api().ajax.reload();
                            }else{
                                layer_error_message(data['msg']);
                            }
                        },
                        error:function(data) {
                            layer_error_message('删除失败!');
                        },
                    });
                });
        }

        $CERTIFICATE_MAIN.getSelectCheckBoxValue=function(){
            var theArray=[];
            $("input[name=checkCertificateList]:checked").each(function() {
                theArray.push($(this).val());
            });
            return theArray;
        }
        $(function(){
            $(document).on("click",".certificateDelSelectBtn",function(){
                var ids=$CERTIFICATE_MAIN.getSelectCheckBoxValue();
                if(ids.length<=0){
                    layer.msg('请选择需要删除的证书数据', {icon:5,time:1000});
                }else{
                    $CERTIFICATE_MAIN.deleteDatas(ids);
                }
            });
            $(document).on("click",".certificateAddBtn",function(){
                layer_show('添加证书','{{url('teacher/certificate/add')}}?teacher_id={{$teacher_id}}',800,500);
            });
        })
    </script>
@endsection